unit Class_PROD;


interface
uses
  Classes,SysUtils,DB,Uni,UniEngine;

type
  TPROD=class(TUniEngine)
  private
    FPRODINDX : Integer;
    FWHOBUILD : Integer;
    FHASHCODE : Integer;
    FPARENTID : Integer;
    FDATALEVL : Integer;
    FDATASTAT : Integer;
    FDATAORDR : Integer;
    FDATADATE : Integer;
    FDATATIME : Extended;
    FKJNDKJQJ : Integer;
    FPRODNAME : string;
    FPRODCODE : string;
    FPRODCOST : Extended;
    FINTMOENY : Extended;
    FOUTMONEY : Extended;
    FPRODMEMO : string;
    FPRODJLDW : Integer;
    FPRODGGXH : string;
    FWARNLESS : Integer;
    FINSERIAL : Integer;
  protected
    procedure SetParameters;override;
    function  GetStrInsert:string;override;
    function  GetStrUpdate:string;override;
    function  GetStrDelete:string;override;
  public
    function  GetStrsIndex:string;override;
  public
    //#function  GetNextIndx:Integer;overload;
    //#function  GetNextIndx(AUniConnection:TUniConnection):Integer;overload;
  public
    function  CheckExist(AUniConnection:TUniConnection):Boolean;override;
  public
    destructor  Destroy; override;
    constructor Create;
  published
    property PRODINDX : Integer read FPRODINDX  write FPRODINDX;
    property WHOBUILD : Integer read FWHOBUILD  write FWHOBUILD;
    property HASHCODE : Integer read FHASHCODE  write FHASHCODE;
    property PARENTID : Integer read FPARENTID  write FPARENTID;
    property DATALEVL : Integer read FDATALEVL  write FDATALEVL;
    property DATASTAT : Integer read FDATASTAT  write FDATASTAT;
    property DATAORDR : Integer read FDATAORDR  write FDATAORDR;
    property DATADATE : Integer read FDATADATE  write FDATADATE;
    property DATATIME : Extended read FDATATIME  write FDATATIME;
    property KJNDKJQJ : Integer read FKJNDKJQJ  write FKJNDKJQJ;
    property PRODNAME : string read FPRODNAME  write FPRODNAME;
    property PRODCODE : string read FPRODCODE  write FPRODCODE;
    property PRODCOST : Extended read FPRODCOST  write FPRODCOST;
    property INTMOENY : Extended read FINTMOENY  write FINTMOENY;
    property OUTMONEY : Extended read FOUTMONEY  write FOUTMONEY;
    property PRODMEMO : string read FPRODMEMO  write FPRODMEMO;
    property PRODJLDW : Integer read FPRODJLDW  write FPRODJLDW;
    property PRODGGXH : string read FPRODGGXH  write FPRODGGXH;
    property WARNLESS : Integer read FWARNLESS  write FWARNLESS;
    property INSERIAL : Integer read FINSERIAL  write FINSERIAL;
  public
    class function  ReadDS(AUniQuery:TUniQuery):TUniEngine;override;
    class procedure ReadDS(AUniQuery:TUniQuery;var Result:TUniEngine);override;
    class function  CopyIt(APROD:TPROD):TPROD;overload;
    class procedure CopyIt(APROD:TPROD;var Result:TPROD);overload;
  end;

implementation


{ TPROD }
procedure TPROD.SetParameters;
var
  I:Integer;
  Param:TUniParam;
  ParamName:string;
begin
  inherited;
  with FUniSQL.Params do
  begin
    case FOptTyp of
      otAddx:
      begin
        for I := 0 to FUniSQL.Params.Count-1 do
        begin

          Param := FUniSQL.Params.Items[I];
          ParamName := FUniSQL.Params.Items[I].Name;
          if ParamName='PROD_INDX' then
          begin
            Param.Value :=  PRODINDX;
          end else
          if ParamName='WHO_BUILD' then
          begin
            Param.Value := WHOBUILD;
          end else
          if ParamName='PROD_CODE' then 
          begin
            Param.Value := PRODCODE;
          end else
          if ParamName='PROD_NAME' then
          begin
            Param.Value := PRODNAME;
          end;
        end;

        {ParamByName('PROD_INDX').Value := PRODINDX;
        ParamByName('WHO_BUILD').Value := WHOBUILD;
        ParamByName('HASH_CODE').Value := HASHCODE;
        ParamByName('PARENT_ID').Value := PARENTID;
        ParamByName('DATA_LEVL').Value := DATALEVL;
        ParamByName('DATA_STAT').Value := DATASTAT;
        ParamByName('DATA_ORDR').Value := DATAORDR;
        ParamByName('DATA_DATE').Value := DATADATE;
        ParamByName('DATA_TIME').Value := DATATIME;
        ParamByName('KJND_KJQJ').Value := KJNDKJQJ;
        ParamByName('PROD_NAME').Value := PRODNAME;
        ParamByName('PROD_CODE').Value := PRODCODE;
        ParamByName('PROD_COST').Value := PRODCOST;
        ParamByName('INT_MOENY').Value := INTMOENY;
        ParamByName('OUT_MONEY').Value := OUTMONEY;
        ParamByName('PROD_MEMO').Value := PRODMEMO;
        ParamByName('PROD_JLDW').Value := PRODJLDW;
        ParamByName('PROD_GGXH').Value := PRODGGXH;
        ParamByName('WARN_LESS').Value := WARNLESS;
        ParamByName('IN_SERIAL').Value := INSERIAL;}
      end;
      otEdit:
      begin
        ParamByName('PROD_INDX').Value := PRODINDX;
        ParamByName('WHO_BUILD').Value := WHOBUILD;
        ParamByName('HASH_CODE').Value := HASHCODE;
        ParamByName('PARENT_ID').Value := PARENTID;
        ParamByName('DATA_LEVL').Value := DATALEVL;
        ParamByName('DATA_STAT').Value := DATASTAT;
        ParamByName('DATA_ORDR').Value := DATAORDR;
        ParamByName('DATA_DATE').Value := DATADATE;
        ParamByName('DATA_TIME').Value := DATATIME;
        ParamByName('KJND_KJQJ').Value := KJNDKJQJ;
        ParamByName('PROD_NAME').Value := PRODNAME;
        ParamByName('PROD_CODE').Value := PRODCODE;
        ParamByName('PROD_COST').Value := PRODCOST;
        ParamByName('INT_MOENY').Value := INTMOENY;
        ParamByName('OUT_MONEY').Value := OUTMONEY;
        ParamByName('PROD_MEMO').Value := PRODMEMO;
        ParamByName('PROD_JLDW').Value := PRODJLDW;
        ParamByName('PROD_GGXH').Value := PRODGGXH;
        ParamByName('WARN_LESS').Value := WARNLESS;
        ParamByName('IN_SERIAL').Value := INSERIAL;
      end;
      otDelt:
      begin
        ParamByName('PROD_INDX').Value := PRODINDX;
        ParamByName('WHO_BUILD').Value := WHOBUILD;

      end;
    end;
  end;
end;

function TPROD.CheckExist(AUniConnection: TUniConnection): Boolean;
begin
  Result:=CheckExist('TBL_PROD',['PROD_INDX',PRODINDX,'WHO_BUILD',WHOBUILD],AUniConnection);
end;

{#function TPROD.GetNextIndx: Integer;
begin

end;}

{#function TPROD.GetNextIndx(AUniConnection: TUniConnection): Integer;
begin

end;}

function TPROD.GetStrDelete: string;
begin
  Result:='DELETE FROM TBL_PROD WHERE   PROD_INDX=:PROD_INDX AND WHO_BUILD=:WHO_BUILD';
end;

function TPROD.GetStrInsert: string;
begin
  Result:='INSERT INTO TBL_PROD'
         +'    ( PROD_INDX, WHO_BUILD, HASH_CODE, PARENT_ID, DATA_LEVL'
         +'    , DATA_STAT, DATA_ORDR, DATA_DATE, DATA_TIME, KJND_KJQJ'
         +'    , PROD_NAME, PROD_CODE, PROD_COST, INT_MOENY, OUT_MONEY'
         +'    , PROD_MEMO, PROD_JLDW, PROD_GGXH, WARN_LESS, IN_SERIAL)'
         +'    VALUES'
         +'    (:PROD_INDX,:WHO_BUILD,:HASH_CODE,:PARENT_ID,:DATA_LEVL'
         +'    ,:DATA_STAT,:DATA_ORDR,:DATA_DATE,:DATA_TIME,:KJND_KJQJ'
         +'    ,:PROD_NAME,:PROD_CODE,:PROD_COST,:INT_MOENY,:OUT_MONEY'
         +'    ,:PROD_MEMO,:PROD_JLDW,:PROD_GGXH,:WARN_LESS,:IN_SERIAL)';
end;

function TPROD.GetStrsIndex: string;
begin
  Result:=Format('%D-%D',[PRODINDX,WHOBUILD]);
end;

function TPROD.GetStrUpdate: string;
begin
  Result:='UPDATE  TBL_PROD SET'
         +'    HASH_CODE=:HASH_CODE,'
         +'    PARENT_ID=:PARENT_ID,'
         +'    DATA_LEVL=:DATA_LEVL,'
         +'    DATA_STAT=:DATA_STAT,'
         +'    DATA_ORDR=:DATA_ORDR,'
         +'    DATA_DATE=:DATA_DATE,'
         +'    DATA_TIME=:DATA_TIME,'
         +'    KJND_KJQJ=:KJND_KJQJ,'
         +'    PROD_NAME=:PROD_NAME,'
         +'    PROD_CODE=:PROD_CODE,'
         +'    PROD_COST=:PROD_COST,'
         +'    INT_MOENY=:INT_MOENY,'
         +'    OUT_MONEY=:OUT_MONEY,'
         +'    PROD_MEMO=:PROD_MEMO,'
         +'    PROD_JLDW=:PROD_JLDW,'
         +'    PROD_GGXH=:PROD_GGXH,'
         +'    WARN_LESS=:WARN_LESS,'
         +'    IN_SERIAL=:IN_SERIAL'
         +'    WHERE PROD_INDX=:PROD_INDX'
         +'    AND   WHO_BUILD=:WHO_BUILD';
end;

constructor TPROD.Create;
begin

end;

destructor TPROD.Destroy;
begin

  inherited;
end;

class function TPROD.ReadDS(AUniQuery: TUniQuery): TUniEngine;
begin
  Result:=TPROD.Create;
  TPROD.ReadDS(AUniQuery,Result);
end;

class procedure TPROD.ReadDS(AUniQuery: TUniQuery; var Result: TUniEngine);
var
  I:Integer;
  Field:TField;
  FieldName:string;
begin
  if Result=nil then Exit;

  with TPROD(Result) do
  begin
    for I:=0 to AUniQuery.Fields.Count-1 do
    begin
      Field:=AUniQuery.Fields.Fields[I];
      //if field.fieldname is not all uppercase,please use uppercase().
      FieldName:=Field.FieldName;
      if FieldName='PROD_INDX' then
      begin
        PRODINDX :=Field.AsInteger;
      end else
      if FieldName='WHO_BUILD' then
      begin
        WHOBUILD :=Field.AsInteger;
      end else
      if FieldName='HASH_CODE' then
      begin
        HASHCODE :=Field.AsInteger;
      end else
      if FieldName='PARENT_ID' then
      begin
        PARENTID :=Field.AsInteger;
      end else
      if FieldName='DATA_LEVL' then
      begin
        DATALEVL :=Field.AsInteger;
      end else
      if FieldName='DATA_STAT' then
      begin
        DATASTAT :=Field.AsInteger;
      end else
      if FieldName='DATA_ORDR' then
      begin
        DATAORDR :=Field.AsInteger;
      end else
      if FieldName='DATA_DATE' then
      begin
        DATADATE :=Field.AsInteger;
      end else
      if FieldName='DATA_TIME' then
      begin
        DATATIME :=Field.AsFloat;
      end else
      if FieldName='KJND_KJQJ' then
      begin
        KJNDKJQJ :=Field.AsInteger;
      end else
      if FieldName='PROD_NAME' then
      begin
        PRODNAME :=Field.AsString;
      end else
      if FieldName='PROD_CODE' then
      begin
        PRODCODE :=Field.AsString;
      end else
      if FieldName='PROD_COST' then
      begin
        PRODCOST :=Field.AsFloat;
      end else
      if FieldName='INT_MOENY' then
      begin
        INTMOENY :=Field.AsFloat;
      end else
      if FieldName='OUT_MONEY' then
      begin
        OUTMONEY :=Field.AsFloat;
      end else
      if FieldName='PROD_MEMO' then
      begin
        PRODMEMO :=Field.AsString;
      end else
      if FieldName='PROD_JLDW' then
      begin
        PRODJLDW :=Field.AsInteger;
      end else
      if FieldName='PROD_GGXH' then
      begin
        PRODGGXH :=Field.AsString;
      end else
      if FieldName='WARN_LESS' then
      begin
        WARNLESS :=Field.AsInteger;
      end else
      if FieldName='IN_SERIAL' then
      begin
        INSERIAL :=Field.AsInteger;
      end;
    end
  end;
end;

class function  TPROD.CopyIt(APROD: TPROD): TPROD;
begin
  Result:=TPROD.Create;
  TPROD.CopyIt(APROD,Result)
end;

class procedure TPROD.CopyIt(APROD:TPROD;var Result:TPROD);
begin
  if Result=nil then Exit;
  Result.PRODINDX :=APROD.PRODINDX;
  Result.WHOBUILD :=APROD.WHOBUILD;
  Result.HASHCODE :=APROD.HASHCODE;
  Result.PARENTID :=APROD.PARENTID;
  Result.DATALEVL :=APROD.DATALEVL;
  Result.DATASTAT :=APROD.DATASTAT;
  Result.DATAORDR :=APROD.DATAORDR;
  Result.DATADATE :=APROD.DATADATE;
  Result.DATATIME :=APROD.DATATIME;
  Result.KJNDKJQJ :=APROD.KJNDKJQJ;
  Result.PRODNAME :=APROD.PRODNAME;
  Result.PRODCODE :=APROD.PRODCODE;
  Result.PRODCOST :=APROD.PRODCOST;
  Result.INTMOENY :=APROD.INTMOENY;
  Result.OUTMONEY :=APROD.OUTMONEY;
  Result.PRODMEMO :=APROD.PRODMEMO;
  Result.PRODJLDW :=APROD.PRODJLDW;
  Result.PRODGGXH :=APROD.PRODGGXH;
  Result.WARNLESS :=APROD.WARNLESS;
  Result.INSERIAL :=APROD.INSERIAL;
end;

end.

